﻿@using Property;
@{
    ViewBag.Title = "NatureIndex";
}
@model string
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-groupview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-detailview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/iconfont.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/demo.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css"/>
<script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
}
<div style="float:left;width:190px;height:100%">
    <div class="content-bar-color" style="height:34px; line-height: 34px; text-align: center">
        性质类别
    </div>
    <div style="padding-top:1px">
        <ul id="tree" class="ztree"></ul>
    </div>
</div>
<div style="position:absolute;left:190px;right:0;height:100%">
    <div id="grid-bundles">
        <input type="hidden" data-filter="true" id="NatureCatalogId" name="NatureCatalogId" />
                </div>
            </div>
            @section foot
{
                <script type="text/javascript">
                    var jsonTree = @MvcHtmlString.Create(Model);
                    var settings = { callback: { onClick: nodeClick } };
                    var zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);

                    function nodeClick(e,treeId, treeNode)
                    {
                        $("#NatureCatalogId").val(treeNode.id);
                        single = treeNode.obj;
                        LoadGridData();
                    }

                    var single = false;
                    function LoadGridData() {
                        checkedRows = new Array();
                        var columns = [[
                            { field: "ck", checkbox: true},
                            { field: "Value", title: "性质内容", width: 180, sortable: true,formatter:function(val,row,index){
                                return "<a>" + val + "</a>";
                            }},
                            { field: "Description", title: "性质说明", width: 400},
                            { field: "NatureCatalogName", title: "性质名称"},
                            { field: "Order", title: "排序", width: 40, sortable: true, halign: "center", align: "center" }
                        ]];
                        var parameter = {
                            title: null,
                            columns: columns,
                            url: "@Url.Content("~/Customer/Nature/GetNatureGridData")",
                            pageNumber: 1,
                            singleSelect:!single,
                            ctrlSelect:!single,
                            onCheck: checkRow,
                            onUncheck: uncheckRow,
                            onCheckAll: checkAllRow,
                            onUncheckAll: uncheckAllRow,
                            onLoadSuccess:loadSuccess
                        };
                        var grid= KingsSharp.GetGridData("#grid-bundles",parameter).Grid;
                    }
                    LoadGridData();

                    var checkedRows = new Array();
                    function loadSuccess()
                    {
                        var rows = $("#grid").datagrid("getRows");
                        $.Enumerable.From(rows).ForEach(function (row,i) {
                            if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == row.Id; }).Count() != 0) {
                                $("#grid").datagrid("checkRow", i);
                            }
                        });
                    }
                    function checkRow(rows,rowData)
                    {
                        if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() == 0)
                        {
                            checkedRows = $.Enumerable.From(checkedRows).Union([rowData]).ToArray();
                        }
                    }
                    function uncheckRow(rows, rowData)
                    {
                        if ($.Enumerable.From(checkedRows).Where(function (x) { return x.Id == rowData.Id; }).Count() > 0) {
                            checkedRows = $.Enumerable.From(checkedRows).Except([rowData]).ToArray();
                        }
                    }
                    function checkAllRow(rows)
                    {
                        checkedRows = $.Enumerable.From(checkedRows).Union(rows).ToArray();
                    }
                    function uncheckAllRow(rows)
                    {
                        checkedRows = $.Enumerable.From(checkedRows).Except(rows).ToArray();
                    }
                    function SaveData(index) {
                        parent.K.layer.callback(index, checkedRows);
                        parent.K.layer.close(index);
                    }
                </script>
            }


